import {LogLanguage} from "../dist/index.js"

// 测试类路径识别
const testCases = [
  // 您提供的实际日志示例
  "2025-08-06 11:23:02,220 INFO  [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] points.PointsProcessor (com.cn.yft.ora.bank.p600030.points.PointsProcessor:64) - 【权益积分通道】 积分发放，方法入参：bankOrder={...}",
  
  // 其他类路径格式
  "2024-01-15 10:30:45 [INFO] [service.SBYBaseService:70] Processing request",
  
  // 带数字的类路径
  "2024-01-15 10:30:45 [INFO] (com.cn.yft.ora.bank.p600030.points.PointsProcessor:64) Database operation",
  
  // 复杂类路径
  "2024-01-15 10:30:45 [INFO] (com.cn.yft.ora.bank.sby.service.SBYBaseService:87) Service call",
  
  // 混合格式
  "2024-01-15 10:30:45 [INFO] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] points.PointsProcessor (com.cn.yft.ora.bank.p600030.points.PointsProcessor:64) - Processing request"
]

console.log("=== 类路径识别测试 ===")

testCases.forEach((testCase, index) => {
  console.log(`\n测试 ${index + 1}:`)
  console.log(`输入: ${testCase}`)
  
  const tree = LogLanguage.parser.parse(testCase)
  let foundNodes = []
  
  tree.iterate({
    enter: (node) => {
      foundNodes.push({
        name: node.type.name,
        from: node.from,
        to: node.to,
        text: testCase.slice(node.from, node.to)
      })
    }
  })
  
  console.log("识别的节点:")
  foundNodes.forEach(node => {
    console.log(`  - ${node.name}: "${node.text}" (${node.from}-${node.to})`)
  })
  
  // 检查类路径节点
  const classPathNodes = foundNodes.filter(node => node.name === 'CLASSPATHExpression')
  
  if (classPathNodes.length > 0) {
    console.log("\n✓ 类路径识别成功:")
    classPathNodes.forEach(node => {
      console.log(`  - CLASSPATHExpression: "${node.text}"`)
    })
  } else {
    console.log("\n✗ 未找到类路径节点")
    
    // 检查是否有括号包围的内容
    const bracketMatches = testCase.match(/\(([^)]+)\)/g)
    if (bracketMatches) {
      console.log("发现括号包围的内容:")
      bracketMatches.forEach(match => {
        console.log(`  - ${match}`)
      })
    }
  }
  
  // 检查其他功能
  const dateNodes = foundNodes.filter(node => node.name === 'DATEExpression')
  const logLevelNodes = foundNodes.filter(node => 
    node.name.includes('Expression') && 
    (node.name.includes('FATAL') || node.name.includes('ERROR') || 
     node.name.includes('INFO') || node.name.includes('WARNING') || 
     node.name.includes('Debug'))
  )
  const tidNodes = foundNodes.filter(node => 
    node.name.includes('TID') || 
    node.text.includes('fcdfba1a21214a8e97c7d8fd1a8aa287')
  )
  
  console.log("\n其他功能检查:")
  console.log(`  - 日期识别: ${dateNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - 日志级别识别: ${logLevelNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - TID识别: ${tidNodes.length > 0 ? '✓' : '✗'}`)
})
